Skip to content

gh-129139: Fix __setstate__ on exhausted list iterators in free-threaded build#146269

Closed
ghost wants to merge 2 commits intomainfrom
unknown repository
Closed

gh-129139: Fix __setstate__ on exhausted list iterators in free-threaded build#146269
ghost wants to merge 2 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 22, 2026

In free-threaded builds, exhausted list iterators signal exhaustion by
setting it_index to -1 without clearing it_seq to NULL (to avoid
expensive atomic refcount operations on the hot path). The existing
it_seq != NULL guard in listiter_setstate and listreviter_setstate
allowed __setstate__ to revive an exhausted iterator by resetting
it_index to a valid value.

This adds an it_index >= 0 check so that __setstate__ is a no-op on
exhausted iterators, consistent with GIL-enabled build behavior.

The same fix is applied to both listiter_setstate and listreviter_setstate,
which share the same pattern.

…ded build

In free-threaded builds, exhausted list iterators signal exhaustion by
setting it_index to -1 without clearing it_seq to NULL. The existing
it_seq != NULL guard in listiter_setstate and listreviter_setstate
allowed __setstate__ to revive an exhausted iterator by resetting
it_index to a valid value.

Add an it_index >= 0 check so that __setstate__ is a no-op on
exhausted iterators, consistent with GIL-enabled build behavior.
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Mar 22, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@ghost ghost closed this by deleting the head repository Mar 27, 2026
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant